const sign_in_btn = document.querySelector("#sign-in-btn");
const sign_up_btn = document.querySelector("#sign-up-btn");
const container = document.querySelector(".container");

sign_up_btn.addEventListener("click", () => {
  container.classList.add("sign-up-mode");
});

sign_in_btn.addEventListener("click", () => {
  container.classList.remove("sign-up-mode");
});
const form = document.querySelector(".sign-in-form")
const submit = document.querySelector('.solid')
submit.onclick = (e) => {
  e.preventDefault();
  const formData = new FormData(form)
  console.log(formData.get('username'), formData.get('password'))
  axios({
    method: 'GET',
    url: 'http://m10.ctymc.cn:24048/user',
  }).then(res => {

    //  function yy() {
    // let v = []
    res.data.forEach(el => {
      console.log(el.username)
      console.log(el.password)
      console.log(formData.get('username'), formData.get('password'))

      if (el.username === formData.get('username')) {
        if (el.password === formData.get('password')) {
          console.log('登录成功')
          alert('登录成功')
          setTimeout(() =>{
            location.href='./index.html'
          },2000)
          return
        }
        return alert('用户名或密码错误')
      }
      // return alert('用户名或密码错误')

    });

   

    console.log(res.data)
  })


}
const form2 =document.querySelector('.sign-up-form')
const submit2 = document.querySelector('.solid2')
submit2.onclick = (e) => {
  e.preventDefault();
  const formData = new FormData(form2)
  console.log(formData.get('username'), formData.get('password'))
  axios({
    method: 'POST',
    url: 'http://m10.ctymc.cn:24048/user',
    data:{
      username:formData.get('username'),
      password:formData.get('password')
    }

  }).then(res => {
      alert("注册成功")
    console.log(res)
  })

}